

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.CdcWaterMonitor;
import com.loong.loong.hik.service.CdcWaterMonitorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 漏水监测
 *
 * @author jinyiang
 * @date 2023-04-11 14:25:48
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cdcwatermonitor" )
@Api(value = "cdcwatermonitor", tags = "漏水监测管理")
public class CdcWaterMonitorController {

    private final  CdcWaterMonitorService cdcWaterMonitorService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cdcWaterMonitor 漏水监测
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_view')" )
    public R getCdcWaterMonitorPage(Page page, CdcWaterMonitor cdcWaterMonitor) {
		return R.ok(cdcWaterMonitorService.page(page, Wrappers.query(cdcWaterMonitor).lambda()
				.like(StringUtils.isNotEmpty(cdcWaterMonitor.getLikeName()), CdcWaterMonitor::getIncident,cdcWaterMonitor.getLikeName())
				.between(StringUtils.isNotEmpty(cdcWaterMonitor.getStartTime())&&StringUtils.isNotEmpty(cdcWaterMonitor.getEndTime()), CdcWaterMonitor::getCreateTime,cdcWaterMonitor.getStartTime(),cdcWaterMonitor.getEndTime()))
		);
    }


    /**
     * 通过id查询漏水监测
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(cdcWaterMonitorService.getById(id));
    }

    /**
     * 新增漏水监测
     * @param cdcWaterMonitor 漏水监测
     * @return R
     */
    @ApiOperation(value = "新增漏水监测", notes = "新增漏水监测")
    @SysLog("新增漏水监测" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_add')" )
    public R save(@RequestBody CdcWaterMonitor cdcWaterMonitor) {
        return R.ok(cdcWaterMonitorService.save(cdcWaterMonitor));
    }

    /**
     * 修改漏水监测
     * @param cdcWaterMonitor 漏水监测
     * @return R
     */
    @ApiOperation(value = "修改漏水监测", notes = "修改漏水监测")
    @SysLog("修改漏水监测" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_edit')" )
    public R updateById(@RequestBody CdcWaterMonitor cdcWaterMonitor) {
        return R.ok(cdcWaterMonitorService.updateById(cdcWaterMonitor));
    }

    /**
     * 通过id删除漏水监测
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除漏水监测", notes = "通过id删除漏水监测")
    @SysLog("通过id删除漏水监测" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_del')" )
    public R removeById(@PathVariable Integer id) {
        return R.ok(cdcWaterMonitorService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param cdcWaterMonitor 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_cdcwatermonitor_export')" )
    public List<CdcWaterMonitor> export(CdcWaterMonitor cdcWaterMonitor) {
        return cdcWaterMonitorService.list(Wrappers.query(cdcWaterMonitor));
    }
}
